﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CreateDeleteTXT
{
    class Program
    {
        static void Main(string[] args)
        {
            if (!File.Exists("F:\\TestTxt.txt"))
            {
                FileStream fs1 = new FileStream("F:\\TestTxt.txt", FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs1);
                sw.WriteLine("Hello Word");
                sw.Close();
                fs1.Close();

                Console.WriteLine("OK");
            }
            else
            {
                FileStream fs = new FileStream("F:\\TestTxt.txt", FileMode.Open, FileAccess.Write);
                StreamWriter sr = new StreamWriter(fs);
                sr.WriteLine("HHHHHHH");//开始写入值
                sr.Close();
                fs.Close();
                Console.WriteLine("OKToo");

                ////删除指定行
                List<string> lines = new List<string>(File.ReadAllLines("F:\\TestTxt.txt"));
                lines.RemoveAt(1);//删除第1行
                File.WriteAllLines("F:\\TestTxt.txt", lines.ToArray());
            }

            Console.ReadKey();


        }
    }
}
